<?php

namespace Platform\Services;

/**
 * 基础服务类
 */
class BaseService {

    const PAGESIZE = 10;

    protected $IS_DEL = 1; //删除状态
    protected $IS_NOT_DEL = 0; //非删除状态
    protected $IS_OPEN = 1; //打开状态 （适用任何开关模块）
    protected $IS_NOT_OPEN = 0; //关闭状态 （适用任何开关模块）
    protected $NEWS = 1;
    protected $VIDEO = 2;

    /**
     * 实例数组
     * @var array
     */
    private static $instance = []; //实例数组
    static private $_instance = null; //当前model服务实例

    public static function getInstance($objName = "") {
        if (!$objName) {
            $objName = get_called_class();
        }
        if (isset(self::$instance[$objName])) {
            self::$_instance = self::$instance[$objName];
        } else {
            self::$_instance = new $objName();
            self::$instance[$objName] = self::$_instance;
        }
        return self::$_instance;
    }

    //__set()方法用来设置私有属性 
    public function __set($name, $value) {
        $this->$name = $value;
    }

    //__get()方法用来获取私有属性 
    public function __get($name) {
        return $this->$name;
    }

    public function __construct() {
        $this->di = \Phalcon\Di::getDefault();
        $this->logger = $this->di->getShared("logger");
        $this->db = $this->di->getShared("db");
        $this->redisCache = $this->di->getShared("redisCache");
    }

}
